﻿using System;
using sharpxbot.Plugins.BibleSearch.Data;

namespace sharpxbot.Plugins.BibleSearch.Utils
{
    public class VerseUtil
    {
        public VerseUtil(BibleCache cache)
        {
            if (cache == null)
                throw new NullReferenceException("Illegal null-reference cache");

            this.cache = cache;
        }

        public VerseInfo GetVerseInfo(Verse v)
        {
            if (v == null)
                return null;

            //fill chapterIndex and book name abbr using cache
            Chapter chapter = cache.GetChapterByID(v.ChapterID);
            if (chapter != null)
            {
                string bookNameAbbr = cache.GetBookNameAbbreviationByID(chapter.BookID);
                if (!String.IsNullOrEmpty(bookNameAbbr))
                {
                    return new VerseInfo()
                    {
                        BookNameAbbreviation = bookNameAbbr,
                        ChapterIndex = Int32.Parse(chapter.ChapterIndex)
                    };
                }
            }

            return null;
        }

        private BibleCache cache;
    }
}
